package com.windfone.common;

import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class StringUtil {

	public static String encode(String str){
		if ( str !=null && !str.equals("")){
			BASE64Encoder b = new BASE64Encoder();
			return b.encode(str.getBytes());
		} else {
			return str;
		}
	}
	 
	public static String decode(String str){
		BASE64Decoder bd = new BASE64Decoder();
		byte[] bt = null;
		try {
			bt = bd.decodeBuffer(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new String(bt);
	}
	
	public static String toFirstLetterUpperCase(String str) {
		if (str == null || str.length() < 2) {
			return str;
		}
		String firstLetter = str.substring(0, 1).toUpperCase();
		return firstLetter + str.substring(1, str.length());
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String str = "name,createTime";
		String[] strs = str.split(",");
		for (int i = 0; i < strs.length; i++) {
			System.out.println(strs[i]);
		}

	}

}
